package com.example.yjhuser.controller;



import com.example.yjhuser.entity.SignIn;
import com.example.yjhuser.service.ISignInService;
import com.example.yjhuser.service.IUsersService;
import com.yc.yjh.entity.Result;
import com.yc.yjh.entity.Users;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 廖老师
 * @since 2023-07-02
 */
@RestController
@RequestMapping("/yjh-user/signIn")
public class SignInController {
    @Resource
    ISignInService signInService;
    @Resource
    IUsersService usersService;
    @RequestMapping("queryInTime")
    public Result queryInTime(@RequestBody String uid){
        List list=signInService.lambdaQuery().eq(SignIn::getUid,uid).list();
        return Result.success("查询成功",list);
    }
    @RequestMapping("addSignTime")
    public Result addSignTime(@RequestBody SignIn signIn){
        signInService.save(signIn);
        return Result.success("签到成功,积分+20");

    }
    @RequestMapping("updateUser")
    public void updateUser(@RequestBody Users user){
        user.setScore(user.getScore()+20);
        usersService.saveOrUpdate(user);
    }
    @RequestMapping("orderBy")
    public Result orderBy(@RequestBody String uid){
        List list=signInService.lambdaQuery()
                .eq(SignIn::getUid,uid)
                .orderByDesc(SignIn::getIntime).last("limit 1").list();
        return Result.success("签到的最新日期",list);
    }
}

